/*
 * @Author: zehao.chen
 * @Date: 2022-08-02 16:57:14
 * @LastEditors: zehao.chen
 * @LastEditTime: 2022-08-14 20:47:45
 * @FilePath: /meeting-admin/src/utils/meeting.js
 * @Description: 
 * 
 */

/**
 * @description: 检查坐标存在，开始坐标不能大于结束坐标
 * @param {*} startX
 * @param {*} startY
 * @param {*} endX
 * @param {*} endY
 * @return {*}
 */
export const checkAreaCoord = (startX, startY, endX, endY) => {
  return startX && startY && endX && endY && startX <= endX && startY <= endY
}


/**
 * @description: 检查新增加的区域是否和已存在的区域重叠
 * @param {*} newArea  新添加的区域
 * @param {*} oldAreaList   已经存在的区域
 * @return {*}
 */
export const checkAreaListCross = (newArea, oldAreaList) => {
  for (let i = 0; i < oldAreaList.length; i++) {
    if (checkAreaCross(newArea, oldAreaList[i]) && newArea?.areaId !== oldAreaList[i].areaId) {
      console.log(oldAreaList[i])
      return true
    }
  }
  return false
}

/**
 * @description: 单个检查新老列表是否重叠
 * @param {*} newArea 
 * @param {*} oldArea 
 * @return {*}
 */
const checkAreaCross = (newArea, oldArea) => {
  return Math.min(newArea.areaEndXcoord, oldArea.areaEndXcoord) >= Math.max(newArea.areaStartXcoord, oldArea.areaStartXcoord) && Math.min(newArea.areaEndYcoord, oldArea.areaEndYcoord) >= Math.max(newArea.areaStartYcoord, oldArea.areaStartYcoord)
}
